package com.xiaotu.controller;

import com.xiaotu.common.BaseController;
import com.xiaotu.dto.BuyPropsCardDto;
import com.xiaotu.dto.ConsumePropsCardDto;
import com.xiaotu.service.PlayerEquipmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

/**
 * @author zhangxiao
 * @create 2022-04-02 10:58
 */
@CrossOrigin
@RestController
@RequestMapping("playerEquipment")
public class PlayerEquipmentController extends BaseController {

    @Autowired
    private PlayerEquipmentService playerEquipmentService;

    /**
     * 消耗道具卡
     *
     * @param consumePropsCardDto
     * @return
     */
    @PostMapping("consumePropsCard")
    public Object consumePropsCard(@Valid ConsumePropsCardDto consumePropsCardDto, BindingResult result) {
        if (result.hasErrors())
            throw new IllegalArgumentException("参数校验失败");
        return playerEquipmentService.consumePropsCard(consumePropsCardDto);
    }

    /**
     * 购买道具卡
     *
     * @param buyPropsCardDto
     * @return
     */
    @PostMapping("buyPropsCard")
    public Object buyPropsCard(@Valid BuyPropsCardDto buyPropsCardDto, BindingResult result) {
        if (result.hasErrors())
            throw new IllegalArgumentException("参数校验失败");
        return playerEquipmentService.buyPropsCard(buyPropsCardDto);
    }

}
